package org.jsola.contract.helper;

import org.jsola.contract.dto.ContractCredentialSiteAddDTO;
import org.jsola.contract.dto.ContractCredentialSiteUpdateDTO;
import org.jsola.contract.entity.ContractCredentialSiteDO;
import org.jsola.contract.query.ContractCredentialSiteQuery;
import org.jsola.contract.service.IContractCredentialSiteService;
import org.jsola.contract.vo.ContractCredentialSiteVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.contract.core.AbstractTest.SITE_ID;



/**
 * 租户开通的电子合同账号
 *
 * @author JanusMix
 */
@Component
public class ContractCredentialSiteTestHelper extends BaseTestHelper {
    
    @Autowired
    private IContractCredentialSiteService contractCredentialSiteService;

    /**
     * 生成add测试数据
     * @return ContractCredentialSiteAddDTO
     */
    public ContractCredentialSiteAddDTO getContractCredentialSiteAddDTO(){
        ContractCredentialSiteAddDTO contractCredentialSiteAddDTO = new ContractCredentialSiteAddDTO();
        contractCredentialSiteAddDTO.setContractCredentialId(getRandomValue("varchar",32));
        contractCredentialSiteAddDTO.setCost(getRandomValue("varchar",255));
        return contractCredentialSiteAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ContractCredentialSiteUpdateDTO
     */
    public ContractCredentialSiteUpdateDTO getContractCredentialSiteUpdateDTO(ContractCredentialSiteVO contractCredentialSiteVO){
        return contractCredentialSiteService.selectDOById(contractCredentialSiteVO.getId(), SITE_ID).to(ContractCredentialSiteUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ContractCredentialSiteQuery
     */
    public ContractCredentialSiteQuery getContractCredentialSiteQuery() {
        ContractCredentialSiteQuery contractCredentialSiteQuery = new ContractCredentialSiteQuery();
        List<ContractCredentialSiteDO> contractCredentialSiteDOList = contractCredentialSiteService.list(new ContractCredentialSiteDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(contractCredentialSiteDOList)) {
            ContractCredentialSiteDO contractCredentialSiteDO = contractCredentialSiteDOList.get(0);
            contractCredentialSiteQuery = contractCredentialSiteDO.to(ContractCredentialSiteQuery.class);
        }
        return contractCredentialSiteQuery;
    }

    /**
     * 保存示例
     * @return ContractCredentialSiteVO
     */
    public ContractCredentialSiteVO saveContractCredentialSiteExample(){
        ContractCredentialSiteAddDTO addDTO = this.getContractCredentialSiteAddDTO();
        ContractCredentialSiteVO contractCredentialSiteVO = contractCredentialSiteService.save(addDTO,buildTokenUser());
        return contractCredentialSiteVO;
    }


}

